<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('案件结案信息')" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-info-add" th:object="${vo}" disabled="true" readonly>
            <input id="caseId" name="caseId" type="hidden" th:field="*{caseId}"/>
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">案由名称：</label>
                <div class="col-sm-8">
                    <input name="caseName" class="form-control" type="text" th:field="*{caseName}" required>
                </div>
            </div>
 
            <div class="form-group">
                <label class="col-sm-3 control-label">案件编号：</label>
                <div class="col-sm-8">
                    <input name="caseNo" class="form-control" type="text" th:field="*{caseNo}" required>
                </div>
            </div>
 
            <div class="form-group">
                <label class="col-sm-3 control-label">更多详情：</label>
                <div class="col-sm-8">
                     <a id="collapse_detail" class="btn btn-primary" data-toggle="collapse" href="#collapseExample" role="button" aria-expanded="false" aria-controls="collapseExample">
						  显示/隐藏
					</a>
                </div>
            </div>
 
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">一、委托方: </label>
                <div class="col-sm-8">
	                <div class="input-group"><button type="button" class="btn btn-white btn-sm" onclick="addRow_principal()"><i class="fa fa-plus"> 增加</i></button>
	                    <!-- <button type="button" class="btn btn-white btn-sm" onclick="deleteRow_principal_after4()"><i class="fa fa-sort"> 排序</i></button> -->
	                	<!-- <button type="button" class="btn btn-white btn-sm" onclick="addRow_principal_empty()"><i class="fa fa-plus"> 增加全新 </i></button> -->
	                </div>
                </div>
                <div name="div_principal_body" id="div_principal_body">
                	<input id="principal_cur_idx" type="hidden" value=""/>
	            	<div th:each="bean,stat:${vo.principal}" name="div_principal" th:id="|div_principal_${stat.index}|">
		                <label class="col-sm-3 control-label is-required" name="div_principal_index">委托方: [[${stat.index+1}]]</label>
		                <div class="col-sm-8" name='div_principal_col_sm'>
		                  <div class="input-group" name='div_principal_input'>
	                  			<!-- hidden begin -->
	          					<input type="hidden" name="caseCustIndex" th:field="*{principal[__${stat.index}__].caseCustIndex}" th:id="|principal_${stat.index}_caseCustIndex|"/>
	          					<input type="hidden" name="caseCustType" th:field="*{principal[__${stat.index}__].caseCustType}" th:id="|principal_${stat.index}_caseCustType|"/>
	          					<input type="hidden" name="custId" th:field="*{principal[__${stat.index}__].custId}" th:id="|principal_${stat.index}_custId|"/>
	          					<input type="hidden" name="custName" th:field="*{principal[__${stat.index}__].custName}" th:id="|principal_${stat.index}_custName|"/>
	          					<input type="hidden" name="certNo" th:field="*{principal[__${stat.index}__].certNo}" th:id="|principal_${stat.index}_certNo|"/>
	          					<input type="hidden" name="custType" th:field="*{principal[__${stat.index}__].custType}" th:id="|principal_${stat.index}_custType|"/>
								<!-- hidden end -->
								<input name="custSelect" th:id="|custSelect_principal_${stat.index}|" type="text" placeholder="请选择客户" class="form-control" 
		                    	    readonly th:value="|${bean.custName}-${bean.certNo}|">
		                    	<span name="selectUserInfo" class="input-group-addon" th:onclick="selectUserInfo_principal([[${stat.index}]])"><i class="fa fa-search"></i></span>
		                    	<span name="deleteRow" class="input-group-addon" th:onclick="deleteRow_principal([[${stat.index}]])"><i class="fa fa-minus"></i></span>
		                  </div>
		                </div>
	                </div>
	           </div>
            </div>
			
			<div class="collapse" id="collapseExample">
  				<div class="card card-body">
            
            <div class="form-group">
                <label class="col-sm-3 control-label">二、利益相对方: </label>
                <div class="col-sm-8">
	                <div class="input-group">
	                	<button type="button" class="btn btn-white btn-sm" onclick="addRow_oppositor()"><i class="fa fa-plus"> 增加</i></button>
	                    <!-- <button type="button" class="btn btn-white btn-sm" onclick="deleteRow_oppositor_after4()"><i class="fa fa-sort"> 排序</i></button> -->
	                	<!-- <button type="button" class="btn btn-white btn-sm" onclick="addRow_oppositor_empty()"><i class="fa fa-plus"> 增加全新 </i></button> -->
	                </div>
                </div>
                <div name="div_oppositor_body" id="div_oppositor_body">
                	<input id="oppositor_cur_idx" type="hidden" value=""/>
	            	<div th:each="bean,stat:${vo.oppositor}" name="div_oppositor" th:id="|div_oppositor_${stat.index}|">
		                <label class="col-sm-3 control-label is-required" name="div_oppositor_index">利益相对方: [[${stat.index+1}]]</label>
		                <div class="col-sm-8" name='div_oppositor_col_sm'>
		                  <div class="input-group" name='div_oppositor_input'>
	                  			<!-- hidden begin -->
	          					<input type="hidden" name="caseCustIndex" th:field="*{oppositor[__${stat.index}__].caseCustIndex}" th:id="|oppositor_${stat.index}_caseCustIndex|"/>
	          					<input type="hidden" name="caseCustType" th:field="*{oppositor[__${stat.index}__].caseCustType}" th:id="|oppositor_${stat.index}_caseCustType|"/>
	          					<input type="hidden" name="custId" th:field="*{oppositor[__${stat.index}__].custId}" th:id="|oppositor_${stat.index}_custId|"/>
	          					<input type="hidden" name="custName" th:field="*{oppositor[__${stat.index}__].custName}" th:id="|oppositor_${stat.index}_custName|"/>
	          					<input type="hidden" name="certNo" th:field="*{oppositor[__${stat.index}__].certNo}" th:id="|oppositor_${stat.index}_certNo|"/>
	          					<input type="hidden" name="custType" th:field="*{oppositor[__${stat.index}__].custType}" th:id="|oppositor_${stat.index}_custType|"/>
								<!-- hidden end -->
								<input name="custSelect" th:id="|custSelect_oppositor_${stat.index}|" type="text" placeholder="请选择客户" class="form-control" 
		                    	    readonly th:value="|${bean.custName}-${bean.certNo}|">
		                    	<span name="selectUserInfo" class="input-group-addon" th:onclick="selectUserInfo_oppositor([[${stat.index}]])"><i class="fa fa-search"></i></span>
		                    	<span name="deleteRow" class="input-group-addon" th:onclick="deleteRow_oppositor([[${stat.index}]])"><i class="fa fa-minus"></i></span>
		                  </div>
		                </div>
	                </div>
	           </div>
            </div>

            <div class="form-group">
                <label class="col-sm-3 control-label">三、第三方: </label>
                <div class="col-sm-8">
	                <div class="input-group">
	                	<button type="button" class="btn btn-white btn-sm" onclick="addRow_thirdParty()"><i class="fa fa-plus"> 增加</i></button>
	                    <!-- <button type="button" class="btn btn-white btn-sm" onclick="deleteRow_thirdParty_after4()"><i class="fa fa-sort"> 排序</i></button> -->
	                	<!-- <button type="button" class="btn btn-white btn-sm" onclick="addRow_thirdParty_empty()"><i class="fa fa-plus"> 增加全新 </i></button> -->
	                </div>
                </div>
                <div name="div_thirdParty_body" id="div_thirdParty_body">
                	<input id="thirdParty_cur_idx" type="hidden" value=""/>
	            	<div th:each="bean,stat:${vo.thirdParty}" name="div_thirdParty" th:id="|div_thirdParty_${stat.index}|">
		                <label class="col-sm-3 control-label is-required" name="div_thirdParty_index">第三方: [[${stat.index+1}]]</label>
		                <div class="col-sm-8" name='div_thirdParty_col_sm'>
		                  <div class="input-group" name='div_thirdParty_input'>
	                  			<!-- hidden begin -->
	          					<input type="hidden" name="caseCustIndex" th:field="*{thirdParty[__${stat.index}__].caseCustIndex}" th:id="|thirdParty_${stat.index}_caseCustIndex|"/>
	          					<input type="hidden" name="caseCustType" th:field="*{thirdParty[__${stat.index}__].caseCustType}" th:id="|thirdParty_${stat.index}_caseCustType|"/>
	          					<input type="hidden" name="custId" th:field="*{thirdParty[__${stat.index}__].custId}" th:id="|thirdParty_${stat.index}_custId|"/>
	          					<input type="hidden" name="custName" th:field="*{thirdParty[__${stat.index}__].custName}" th:id="|thirdParty_${stat.index}_custName|"/>
	          					<input type="hidden" name="certNo" th:field="*{thirdParty[__${stat.index}__].certNo}" th:id="|thirdParty_${stat.index}_certNo|"/>
	          					<input type="hidden" name="custType" th:field="*{thirdParty[__${stat.index}__].custType}" th:id="|thirdParty_${stat.index}_custType|"/>
								<!-- hidden end -->
								<input name="custSelect" th:id="|custSelect_thirdParty_${stat.index}|" type="text" placeholder="请选择客户" class="form-control" 
		                    	    readonly th:value="|${bean.custName}-${bean.certNo}|">
		                    	<span name="selectUserInfo" class="input-group-addon" th:onclick="selectUserInfo_thirdParty([[${stat.index}]])"><i class="fa fa-search"></i></span>
		                    	<span name="deleteRow" class="input-group-addon" th:onclick="deleteRow_thirdParty([[${stat.index}]])"><i class="fa fa-minus"></i></span>
		                  </div>
		                </div>
	                </div>
	           </div>
            </div>
           
			<div class="form-group">
				<label class="col-sm-3 control-label is-required">选择律师：</label>
				<div class="col-sm-8">
					<div class="input-group">
	                	<input type="hidden" name="lawyerId" id="input_lawyerId" th:field="*{lawyerId}" />
						<input type="text" name="lawyer" id="input_lawyer" placeholder="请选择律师" class="form-control" 
		                    	    readonly th:field="*{lawyer}">
		                <span name="select_lawyer" id="btn_lawyer" 
		                	class="input-group-addon" th:onclick="#"><i class="fa fa-search"></i></span>
					</div>
				</div>
			</div>

            <div class="form-group">    
                <label class="col-sm-3 control-label">备注：</label>
                <div class="col-sm-8">
                    <input name="remark" class="form-control" type="text" th:field="*{remark}">
                </div>
            </div>
            
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">案件类型：</label>
                    <div id="element_ct" class="row">
                        <div class="col-sm-2">
                          <input id="caseTypeId" name="caseTypeId" type="hidden" th:field="*{caseTypeId}"/>
                            <select class="type form-control m-b" data-first-title="请选择">
			                  <option value="">请选择</option>
			                  <option th:value="*{caseTypeId}" th:selected="1"></option>
			                </select>
		                </div>
                        <label class="col-sm-2 control-label">
						&nbsp;&nbsp;&nbsp;&nbsp;诉讼类型：
		                </label>
		                <div class="col-sm-2">
			                <select class="router form-control m-b" th:field="*{litigateTypeId}" data-first-title="请选择">
			                  <option value="">请选择</option>
			                  <option th:value="*{litigateTypeId}" th:selected="1"></option>
			                </select>
		                </div>
                	</div>
            </div>
                                    
            </div>
			</div>
            
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">案件阶段：</label>
                    <div id="element_ct" class="row">
                        <div class="col-sm-2">
                          <input id="casePhaseId" name="casePhaseId" type="hidden" th:field="*{casePhaseId}"/>
			             	<select name="select_case_phase" class="form-control m-b">
			                    <option value="">请选择</option>
				      			<option th:each="u : ${casePhases}" th:text="${u.casePhaseName}" th:value="${u.casePhaseId}" th:field="*{casePhaseId}"></option>
				   			</select>
							<a id="a_edit_court" href="javascript:void(0)" th:onclick="|viewCourtInfo(${vo.caseId})|"><i class='fa fa-edit'></i>查看法院信息</a>
		                </div>
                        <label class="col-sm-2 control-label">
						&nbsp;&nbsp;&nbsp;&nbsp;案件状态：
		                </label>
		                <div class="col-sm-2">
			                <div th:switch="${vo.status}">
				        <span th:case="0">
				        	<input type="text" class="form-control" readonly value="已登记" /></span>
				        <span th:case="1">
				        	<input type="text" class="form-control" readonly value="已立案" /></span>
				        <span th:case="2">
				        	<input type="text" class="form-control" readonly value="进行中" /></span>
				        <span th:case="3">
				        	<input type="text" class="form-control" readonly value="已结案" /></span>
				        <span th:case="4">
				        	<input type="text" class="form-control" readonly value="已归档" /></span>
				        <span th:case="*">
							<input type="text" class="form-control" readonly value="初始化" /></span>
					</div>
		           </div>
               </div>
            </div>          
                      
        </form>

		<div class="form-horizontal m" id="div-info-add" th:object="${vo}" disabled="true" readonly>

            <div class="form-group" th:if="${vo.status=='3'}">
                <label class="col-sm-3 control-label">【结案】交付件：</label>
                <div id="element_casePhases" class="row">                                                                                                                                     
                 	<div class="col-sm-8">
	                	<input id="attach_cur_idx" type="hidden" value=""/>
						<table class="table table-hover">
					    <thead>
					    <tr>
					        <th width="1%">No</th>
					        <th width="24%">交付件名</th>
					        <th width="45%">交付件状态</th>
					        <th width="10%">提醒</th>
					        <th width="20%">备注</th>
					    </tr>
					    </thead>
					    <tbody>
						    <tr th:each="bean,stat:${vo.closedItems}">
						        <td>
								 	<input type="hidden" th:field="*{closedItems[__${stat.index}__].casePhaseIdx}"/>
								 	<input type="hidden" th:field="*{closedItems[__${stat.index}__].casePhaseItem}" />
								 	<label>
								 	  [[${bean.casePhaseIdx}]].
								 	</label>
						        </td>
						        <td>
								 	<label>
								 	  <!--
								 	  <font color="red" th:if="${bean.mustbe==1}">*</font>
								 	  <span th:text="|*{phaseItems[__${stat.index}__].casePhaseIdx}. *{phaseItems[__${stat.index}__].casePhaseItem}|"></span>
								 	  -->
								 	  <font color="red" th:if="${bean.mustbe==1}">*</font>
								 	  [[${bean.casePhaseItem}]]
								 	</label>
						        </td>
						        <td>
					            	<table>
					            	<tbody>
					            	  <tr>
					            	    <td>
							                <form method="post" th:id="|form_upload${bean.caseId}_${bean.casePhaseIdx}|"
							                	th:action="@{/biz/caseinfo/closed/upload}"
							                	enctype="multipart/form-data">
									          <input type="hidden" name="caseId" th:value="${bean.caseId}">
									          <input type="hidden" name="casePhaseId" th:value="${bean.casePhaseId}">
											  <input type="hidden" name="idx" th:value="${bean.casePhaseIdx}">
						                      <input type="file" name="file">
							                </form>
						                </td>
					            	    <td>
						                    &nbsp;&nbsp;&nbsp;
						                    <a href="javascript:void(0)" name="btn_upload"
						 						th:onclick="|document.getElementById('form_upload${bean.caseId}_${bean.casePhaseIdx}').submit()|">上传</a>
					            	    </td>
					            	  </tr>
							          <tr th:each="file, fileStat:${bean.group.files}">
							            <td>[[${fileStat.index+1}]].&nbsp;[[${file.name}]]</td>
							            <td>
							              <a name="btn_download"
							                th:href="@{'/biz/caseinfo/closed/download/' + ${bean.caseId} + '/' + ${bean.casePhaseId} + '/' + ${bean.casePhaseIdx} + '/' + ${file.name}}">下载</a>
							              &nbsp;
							              <a th:href="@{'/biz/caseinfo/closed/delete/' + ${bean.caseId} + '/' + ${bean.casePhaseId} + '/' + ${bean.casePhaseIdx} + '/' + ${file.name}}" 
							              	th:fileName="${file.name}" name="btn_delete" title="Delete this file" 
							              		th:onclick="return confirm('是否确定删除['+[[${file.name}]]+']?')">删除</a>
							            </td>
							          </tr>
							        </tbody>
							        </table>
						        </td>
						        <td></td>
						        <td>
			            	    	<span th:if="${bean.casePhaseIdx==curIdx}">
				            	  	<p th:if="${message ne null}" class="alert alert-primary">[[${message}]]</p>
				            	  	</span>
						        </td>
						    </tr>
					    </tbody>
					</table>

		            </div>
              	</div>
            </div>
        </div>

    </div>
    
    <div class="row">
        <div class="col-sm-offset-5 col-sm-10">
			<div th:switch="${vo.status}">
		        <span th:case="2">
		        	<button type="button" class="btn btn-sm btn-primary" onclick="submitHandler()"><i class="fa fa-check"></i>结 案</button>&nbsp;
		        	<button type="button" class="btn btn-sm btn-danger" onclick="closeItem()"><i class="fa fa-reply-all"></i>关 闭 </button>
		        	</span>
		        <span th:case="*">
		        	<button type="button" class="btn btn-sm btn-danger" onclick="closeItem()"><i class="fa fa-reply-all"></i>关 闭 </button>
					</span>
			</div>
        </div>
    </div>
    
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: jquery-cxselect-js" />
    
	<script type="text/javascript">
		window.onload=function () {
 			$('#form-info-add').find('input').attr('readonly',true);
			$('#form-info-add').find('radio').attr('readonly',true);
			$('#form-info-add').find('select').attr('readonly',true);
			$('#form-info-add').find('select').attr('disabled',true);
			$('#form-info-add').find('button').attr('readonly',true);
			$('#form-info-add').find('button').attr('disabled',true);
			
			$('#collapse_detail').attr('disabled',false);
			$('#collapse_detail').attr('readonly',false);
		}
	</script>

    <script th:inline="javascript">
        var prefix = ctx + "biz/caseinfo/closed"
        $("#form-info-add").validate({
            focusCleanup: true
        });

        function submitHandler_simple() {
            if ($.validate.form()) {
                var data = $("#form-info-add").serializeArray();
                $.operate.saveTab(prefix + "/edit", data);
            }
        }
        
        function submitHandler() {
        	$.modal.confirm("要结案当前案件信息吗?", function() {
        		doSubmitHandler();
    		});
        }
        
	    function doSubmitHandler(){
	    	$.ajax({
	            url: prefix + "/edit",
	            data: $('#form-info-add').serialize(),
	            type: "post",
	            success: function(result) {
	            	if (result.code == web_status.SUCCESS) {
	            		layer.msg("保存成功,正在刷新数据请稍候……", {
		            	    icon: 1,
		            	    time: 500,
		            	    shade: [0.1, '#8F8F8F']
		            	},function() {
		            		location.reload();
		            	});
	            	} else {
	            		alert(result.msg);
	            	}
	            }
	        })
	    }

        function secondHandler() {
            if ($.validate.form()) {
                var data = $("#form-info-add").serializeArray();
                /* $.operate.saveTab(prefix + "/check", data); */
            }
        }
   </script>
   
	<script th:inline="javascript">
		// 直接返回获取
		var ctData = [[${ctData}]];
		$('#element_ct').cxSelect({
		  selects: ['type', 'router'],
		  jsonValue: 'v',
		  data: ctData
		});
	</script>
	
	<script type="text/javascript">
	    // viewCourtInfo
	    function viewCourtInfo(caseId) {
	    	var url = ctx + "biz/caseinfo/court/view/" + caseId;
			var options = {
				title: '查看法院信息',
				btn: ['关闭'],
				url: url,
				yes: function (index, layero) {
                    $.modal.close(index);
                    /* $.table.refresh(); *///关闭后刷新表格数据（不刷新页面）
                }
			};
			$.modal.openOptions(options);
	    }
	</script>

</body>
</html>